import { Sdk_Platform, OPPO_AD_CONFIG } from '../../frame/constants';
import { Control_Listen, PlayGround_Listen, UI_Layer, UI_Listen } from "../../config/ui_def";

cc.Class({
    extends: cc.Component,

    properties: {
        icon_node: cc.Node,
        icon_widge: cc.Widget
    },


    // onLoad () {},

    start() {

    },

    // update (dt) {},


    initPage() {

    },
    updatePage(param) {
        // console.log(this.node.parent)
        this.icon_widge.updateAlignment()
        this.ani()
    },




    closeUI() {
        this.stopSchedule()
    },

    stopSchedule() {
        // this.unschedule(this.ani)
        if (this.tweenAni) {
            this.tweenAni.stop()
            this.tweenAni = null
        }
    },

    ani() {
        if (this.icon_node) {
            this.tweenAni = cc.tween(this.icon_node)
                .repeatForever(
                    cc.tween()
                        .to(0.2, { scale: 1.2 })
                        .to(0.1, { scale: 1 })
                        .to(0.2, { scale: 1.2 })
                        .to(0.1, { scale: 1 })
                        .call(() => {
                            this.node.setScale(1)
                        })
                        .delay(2)
                )
                .start()
        }
    },

    clickServer() {
        let team = he.local.getJson('team', 'user')
        let teamGrp = []
        for (let i = 0; i < team.length; i++) {
            if (team[i].order > 0) {
                teamGrp.push(team[i])
            }
        }
        let idGrp = { '1001': 3009, '1002': 3010, '1003': 3011, '1004': 3012, '1005': 3030 }
        let randomId = idGrp[`${teamGrp[this.randomNum(0, teamGrp.length - 1)].id}`]
        let info = { id: randomId, lv: 3 }
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'tryoutPage',
                    skillInfo: info,
                    cover: true
                })
                break
            case Sdk_Platform.VIVO:
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'tryoutPage',
                    skillInfo: info,
                    cover: true
                })
                break
            case Sdk_Platform.UC:
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'tryoutPage',
                    skillInfo: info,
                    cover: true
                })
                break
            case Sdk_Platform.OPPO:
                break
            default:
                gg.uiManager.addPage(UI_Layer.Cover, {
                    name: 'tryoutPage',
                    skillInfo: info,
                    cover: true
                })
                break
        }
    },

    //范围内的随机数
    randomNum(minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum + 1, 10);
                break;
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                break;
            default:
                return 0;
                break;
        }
    },

});
